<?php defined('SYSPATH') or die('No direct script access.');

class text extends text_Core {

	private static function resolveArgs($allMethodArgs, $declaredParamCount = 1) {
		$args = $allMethodArgs;
		// The first item of the array is $key. Other arguments may come as an array or separate values;
		if (count($args) > $declaredParamCount && is_array($args[$declaredParamCount])) {
			$args = $args[$declaredParamCount];
		}
		else {
			$args = array_slice($args, $declaredParamCount);
		}
		return $args;
	}
	
	public static function getEscaped($key) {
		$args = self::resolveArgs(func_get_args());
		return html::escape(self::get($key, $args));
	}
	
    public static function get($key) {
        $args = self::resolveArgs(func_get_args());
        
        if (! $args && strpos($key, ' ')) {
            return $key;
        }
        
        if (substr($key, 0, 2) != 't.') {
            $key = 't.' . str_replace('.', '-', $key);
        }
        return Kohana::lang($key, $args);
    }

    public static function getInLang($language, $key) {
    	$args = self::resolveArgs(func_get_args(), 2);
    	if (! $args && strpos($key, ' ')) {
    		return $key;
    	}
    	
    	if (substr($key, 0, 2) != 't.') {
    		$key = 't.' . str_replace('.', '-', $key);
    	}
    	return Kohana::langByLocale($language, $key, $args);
    }
}
